package com.leetcode.week.week292;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
 * @author angzhijin
 * @Description
 * @create 2022-05-08 11:06 上午
 */
public class week3 {
    public static void main(String[] args) {
        System.out.println(countTexts("22233"));

        System.out.println(countTexts("22222"));

        System.out.println(countTexts("222222222222222222222222222222222222"));

    }

    static String[] button = new String[]{"","", "abc", "def","ghi","jkl","mno","pqrs","tuv","wxyz"};
    static int MOD = 1000000007;
    public static int countTexts(String pressedKeys) {
        int[] dp = new int[pressedKeys.length()+1];
        dp[0]=1;
        int l=0;
        for (int i = 1; i <= pressedKeys.length(); i++) { // 第i个输入
            if(i>=2 && pressedKeys.charAt(i-1)==pressedKeys.charAt(i-2)){ // 重复输入
                l++;
            }else{
                l=1;
            }
            int input = pressedKeys.charAt(i-1)-'0';
            for (int j = 1; j <= Math.min(l, button[input].length()); j++) {  // 在前j次的基础上按j次
                dp[i] = (dp[i] + dp[i-j])%MOD;
            }
        }
//        System.out.println(Arrays.toString(dp));
        return dp[pressedKeys.length()];
    }

}
